#ifndef SYS_IOCTL_H_
#define SYS_IOCTL_H_

#include <stdint.h>

/******************** Serial IOCTL ********************/
/* Stop bit selections */
typedef enum {
        SERIAL_STOP_0_5 = 0,
        SERIAL_STOP_1,
        SERIAL_STOP_1_5,
        SERIAL_STOP_2
} serial_stop_bits_t;

/* Parity modes */
typedef enum {
        SERIAL_PARITY_NONE = 0,
        SERIAL_PARITY_EVEN,
        SERIAL_PARITY_ODD,
        SERIAL_PARITY_MARK,
        SERIAL_PARITY_SPACE
}serial_parity_t;

/* Word length */
typedef enum {
        SERIAL_WORD_LENGTH_5 = 5,
        SERIAL_WORD_LENGTH_6,
        SERIAL_WORD_LENGTH_7,
        SERIAL_WORD_LENGTH_8,
        SERIAL_WORD_LENGTH_9
}serial_word_length_t;

typedef enum {
        SERIAL_FLOW_NONE = 0,
        SERIAL_FLOW_XONXOFF_RX = (1 << 0), /* receive flow control, send xon/xoff when necessary */
        SERIAL_FLOW_XONXOFF_TX = (1 << 1), /* transmit flow control, act on received xon/xoff */
        SERIAL_FLOW_RTSCTS_RX = (1 << 2),  /* receive flow control, send RTS when necessary */
        SERIAL_FLOW_RTSCTS_TX = (1 << 3),  /* transmit flow control, act when not CTS */
        SERIAL_FLOW_DSRDTR_RX = (1 << 4),  /* receive flow control, send DTR when necessary */
        SERIAL_FLOW_DSRDTR_TX = (1 << 5)  /* transmit flow control, act when not DSR */
}serial_flow_ctrl_t;

typedef struct {
        uint32_t baud;
        serial_stop_bits_t stop;
        serial_parity_t parity;
        serial_word_length_t word_length;
        serial_flow_ctrl_t flow_ctrl;
}serial_info_t;

#define IOCTL_SERIAL_SET_PARAM          0x434F4D01
#define IOCTL_SERIAL_GET_PARAM          0x434F4D02
#define IOCTL_SERIAL_CLR_TXBUF          0x434F4D03
#define IOCTL_SERIAL_CLR_RXBUF          0x434F4D04

/*  For weitch serial */
typedef enum {
	 SERIAL_VIR_MIN=4,
        SERIAL_Y0_FIG=SERIAL_VIR_MIN,
        SERIAL_Y1_MAGC,
        SERIAL_Y2_ID,
        SERIAL_Y3_SCAN,
        SERIAL_VIR_MAX,
}serial_switch_dev_t;
#define IOCTL_SERIAL_SWITCH	0x434F4D07

/******************** ICC IOCTL ********************/
#define IOCTL_ICC_SELECT_SLOT           0x49434301
#define IOCTL_ICC_POWERUP               0x49434302
#define IOCTL_ICC_POWERDOWN             0x49434303
#define IOCTL_ICC_APDU                  0x49434304
#define IOCTL_ICC_PASSWORD		0x49434305
#define IOCTL_ICC_ADDR			0x49434306

#define EX_BUF_LEN 300

typedef struct {
        unsigned char exbuf[EX_BUF_LEN];
        int inlen;
        int resp;
}icc_ex_t;

/******************** Crypto IOCTL ********************/
typedef struct {
        int explen;
        uint8_t *exp;
        int modlen;
        uint8_t *mod;
}rsa_key_t;

#define IOCTL_CRYPTO_SET_KEY            0x43525901
#define IOCTL_CRYPTO_SET_ENCRYPT        0x43525902
#define IOCTL_CRYPTO_SET_DECRYPT        0x43525903

#define IOCTL_CRYPTO_SET_DES_KEYLEN     0x43525911
#define IOCTL_CRYPTO_SET_AES_KEYLEN     0x43525912
#define IOCTL_CRYPTO_SET_RNG_ENTROPY    0x43525921

/******************** LCD IOCTL ********************/
#define IOCTL_LCD_GET_INFO      0x4C434401
#define IOCTL_LCD_UPDATE        0x4C434402
#define IOCTL_LCD_BL            0x4C434403
#define IOCTL_LCD_ATTRIBUTE          0x4C434500
#define IOCTL_LCD_ATTRIBUTE_GRAY          0x01
#define IOCTL_LCD_ATTRIBUTE_TITLE          0x02

typedef struct {
        uint32_t width;
        uint32_t height;
        uint32_t fbuf_len;
        uint8_t * fbuf;
}lcd_info_t;

typedef struct {
        uint32_t x;
        uint32_t y;
        uint32_t w;
        uint32_t h;
}lcd_block_t;
typedef struct {
	uint8_t index;
	uint8_t flag;	
}lcd_title_t;


/******************** KEY IOCTL ********************/
#define IOCTL_KEY_BEEP_ONOFF      0x4B455901

int ioctl(int d, int request, void *arg);

#define IOCTL_MAGC_START	0x44000001
#define IOCTL_MAGC_PARAM	0x44000002
#define IOCTL_MAGC_STOP		0x44000003

/******************** PRINTER IOCTL ********************/
#define IOCTL_PRINT_INIT		0x4E434401
#define IOCTL_PRINT_EXIT		0x4E434402
#define IOCTL_PRINT_FLUSH		0x4E434403
#define IOCTL_PRINT_SET_HEATTIME 		0x4E434404
#define IOCTL_PRINT_GET_STATUS			0x4E434405


/*********************** ADC IOCTL **********************/
#define IOCTL_ADC_SELECT_CHANNEL	0xa8404250
#define IOCTL_ADC_READ_CHANNEL		0xa8404251

/*************************AUDIO IOCTL**************************/

typedef struct {
	uint32_t tx_channel; 
	uint32_t baud;
	uint32_t level_width;
}audio_config_t;

#define IOCTL_AUDIO_PARAM 0X3B4055A0
//#define IOCTL_AUDIO_CHANNEL 0X3B4055A1

/*************************Telephone*******************************/
#define IOCTL_TEL_HANDFREE	0xa8000424
#define	IOCTL_TEL_CID_CODE	0xa8000425
#define IOCTL_TEL_STATUS	0xa8000426
#define IOCTL_TEL_CLR_RXBUF	0xa8000427
#define IOCTL_TEL_DIAL_ON	0xa8000428


#define IOCTL_TEL_FSK_RXSTART	0xa8000429
#define IOCTL_TEL_FSK_TX	0xa8000430


#define IOCTL_TEL_DTMF_RXSTART	0xa8000431
#define IOCTL_TEL_DTMF_TX	0xa8000432

#define IOCTL_TEL_FSK_DTMF_STOP	0xa8000433
#define IOCTL_TEL_MUTE_ONOFF	0xa8000434

#define IOCTL_TEL_TX_PARAM	0xa8000435
#define IOCTL_TEL_RX_PARAM	0xa8000436

#endif /* SYS_IOCTL_H_ */
